<!DOCTYPE html>
<html>
	{include file="public1/_header" /}
	<body>
		<div class="x-nav">
			<span class="layui-breadcrumb">
				<a href="">首页</a>
				<a>
					<cite>校园活动</cite></a>
			</span>
			<a class="layui-btn layui-btn-small" style="float:right" onclick="location.reload()" title="刷新">
				<i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
			</a>
		</div>
		
		<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<div class="layui-card">
						<div class="layui-card-body">
							
							<div class="layui-tab layui-tab-card" lay-filter="test">
							  <ul class="layui-tab-title">
									<li lay-id="1" class="layui-this">相册风采</li>
									<li lay-id="2">视频风采</li>
							  </ul>
							  <div class="layui-tab-content">
							    <div class="layui-tab-item layui-show">
							      <blockquote class="layui-elem-quote layui-quote-nm">
							      	<form class="layui-form layui-col-space5" onsubmit="return false;" lay>
							      		<div class="layui-input-inline layui-show-xs-block">
							      			<input class="layui-input" lay-verify="required" placeholder="请输入标题" name="title" id="title1">
							      		</div>
							      		<div class="layui-input-inline layui-show-xs-block">
							      			<button class="layui-btn" lay-submit="" lay-filter="picSerach">查询</button>
											<button class="layui-btn  layui-btn-primary" id="picRest">重置</button>
							      		</div>
							      	</form>
							      </blockquote>
							      <table class="layui-hide" id="test" lay-filter="test"></table>
							    </div>
								<div class="layui-tab-item">
								  <blockquote class="layui-elem-quote layui-quote-nm">
								  	<form class="layui-form layui-col-space5" onsubmit="return false;">
								  		<div class="layui-input-inline layui-show-xs-block">
								  			<input class="layui-input" lay-verify="required" placeholder="请输入标题" name="title" id="title2">
								  		</div>
								  		<div class="layui-input-inline layui-show-xs-block">
								  			<button class="layui-btn" lay-submit="" lay-filter="videoSerach">查询</button>
											<button class="layui-btn  layui-btn-primary" id="videoRest">重置</button>
								  		</div>
								  	</form>
								  </blockquote>
								  <table class="layui-hide" id="video" lay-filter="video"></table>
								</div>
							  </div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script type="text/html" id="toolbarDemo">
			<div class="layui-btn-container">
					<button class="layui-btn layui-btn-sm" lay-event="add">
						<i class="layui-icon">&#xe642;</i>添加
					</button>
					<button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="getCheckLength">
						<i class="layui-icon">&#xe642;</i>删除
					</button>
				</div>
		</script>
		<script type="text/html" id="barDemo">
			<!-- <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="view">查看</a> -->
			<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
			<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
		</script>
		
		
		<script type="text/html" id="videoToolbar">
			<div class="layui-btn-container">
					<button class="layui-btn layui-btn-sm" lay-event="add">
						<i class="layui-icon">&#xe642;</i>添加
					</button>
					<button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="getCheckLength">
						<i class="layui-icon">&#xe642;</i>删除
					</button>
				</div>
		</script>
		<script type="text/html" id="videoBar">
			<!-- <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="view">查看</a> -->
			<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
			<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
		</script>
		<script type="text/javascript">
			var url = "__STATIC__/admin/"
			layui.extend({
				notice: 'notice/notice'
			}).use(['util', 'laydate', 'table','element','notice'], function() {
				var table = layui.table;
				var form = layui.form;
				var util = layui.util;
				var element = layui.element;
				var notice = layui.notice;
				var tableIns = table.render({
					id: 'testReload',
					elem: '#test',
					url: "{:url('lists')}",
					method: "POST",
					request: {
						pageName: 'offset', //页码的参数名称，默认：page
						limitName: 'limit' //每页数据量的参数名，默认：limit
					},
					where: {
						is_school_msg: 1,
						type:1
					},
					toolbar: '#toolbarDemo',
					cols: [
						[{
							type: 'checkbox',
							fixed: 'left',
							width: 80
						}, {
							field: 'sort',
							title: "排序",
							width: 80,
							edit: true,
							sort: true
						}, {
							field: 'title',
							title: "标题"
						}, {
							field: 'pics',
							title: "相册",
							sort: true,
							templet: function(d) {
								var logoSrc = "";
								 layui.each(d.pics, function(index, item){
									 logoSrc += "<img src='" + item.thumb + "'  width='35' height='26' style='border:1px solid #ccc;box-sizing:border-box' />";
								 })
								return logoSrc;
							},
							event:"nameClick"
						}, {
							field: 'created_at',
							title: "发布日期",
							sort: true
						}, {
							field: 'created_at',
							title: "缩略图",
							width: 80,
							templet: function(d) {
								if (d.image) {
									var logoSrc = "<img src='" + d.image + "'  width='35' height='26' style='border:1px solid #ccc;box-sizing:border-box' />";
								} else {
									var logoSrc = "<img src='" + url + "images/imageno.png' width='40' />";
								}
								return logoSrc;
							},
							event:"nameClick"
						}, {
							field: 'platform',
							title: "来源",
							width: 80,
							templet: function(d) {
								if (d.platform == 1) {
									var check = "后台";
								} else if (d.platform == 2) {
									var check = "APP";
								}else if (d.platform == 3) {
									var check = "其他";
								}
								return check;
							},
							sort: true
						}, {
							field: 'istop',
							title: "置顶",
							width: 80,
							templet: function(d) {
								if (d.istop == 1) {
									var check = "<input type='checkbox' value='" + d.id +
										"' lay-filter='istop' lay-skin='switch' lay-text='是|否' checked>";
								} else if (d.istop == 0) {
									var check = "<input type='checkbox' value='" + d.id +
										"' lay-filter='istop' lay-skin='switch' lay-text='是|否'>";
								}

								return check;
							}
						}, {
							field: 'show',
							title: "显示",
							width: 80,
							templet: function(d) {
								if (d.show == 1) {
									var check = "<input type='checkbox' value='" + d.id +
										"' lay-filter='show' lay-skin='switch' lay-text='是|否' checked>";
								} else if (d.show == 0) {
									var check = "<input type='checkbox' value='" + d.id +
										"' lay-filter='show' lay-skin='switch' lay-text='是|否'>";
								}

								return check;
							}
						}, {
							fixed: 'right',
							title: "{:lang('action')}",
							toolbar: '#barDemo',
							width: 180
						}]
					],
					page: true
				});

				//头工具栏事件
				table.on('toolbar(test)', function(obj) {
					var checkStatus = table.checkStatus(obj.config.id);
					switch (obj.event) {
						case 'getCheckLength':
							var data = checkStatus.data;

							if (data.length < 1) {
								layer.msg('您最少选择一个选项进行操作');
								return false;
							}
							var ids = [];
							data.forEach(function(item, index) {
								ids.push(item.id)
							})
							parent.layer.confirm('确认要删除这些内容？', function() {
								$.post("{:url('delete')}", {
									ids: ids,
									user_id: "{$Think.session.admin.id}"
								}, function(res) {
									if (res.status == 1) {
										parent.layer.msg('删除成功', {
											icon: 1,
											time: 300
										}, function() {
											tableIns.reload()
										});
									} else {
										parent.layer.msg(res.message)
									}
								})
							});

							break;
						case 'add':
							parent.layer.open({
								title: "图片风采",
								type: 2,
								area: ['1000px', '680px'],
								content: "{:url('add')}",
								success: function() {
									top.layerFrameConfig.iframeB = {
										info: tableIns
									}
								}
							});
							break;
					};
				});
				
				

				//监听行工具事件
				table.on('tool(test)', function(obj) {
					var data = obj.data;
					var param = {
						ids: data.id,
						user_id: "{$Think.session.admin.id}"
					}
					if (obj.event === 'del') {
						parent.layer.confirm('真的要删除这条内容么？', function(index) {
							$.post("{:url('delete')}", param, function(res) {
								if (res.code == 0) {
									parent.layer.msg('删除成功', {
										icon: 1,
										time: 300
									}, function() {
										parent.layer.close(index);
										tableIns.reload()
									});
								} else {
									parent.layer.msg(res.message)
								}
							})

						});
					} else if (obj.event === 'edit') {
						parent.layer.open({
							title: "{:lang('edit')}",
							type: 2,
							area: ['1000px', '680px'],
							content: "{:url('edit')}?id=" + data.id,
							success: function() {
								top.layerFrameConfig.iframeB = {
									info: tableIns
								}
							}
						});
					} else if (obj.event === 'view') {
						parent.layer.open({
							title: "详情",
							type: 2,
							area: ['1000px', '680px'],
							content: "{:url('view')}?id=" + data.id,
							success: function() {
								top.layerFrameConfig.iframeB = {
									info: tableIns
								}
							}
						});
					}else if(obj.event === 'nameClick'){
						if(obj.data.pics != ''){
							layer.photos({
								anim: 0,
								shade: [0.1, '#333'],
							    photos: { "data": obj.data.pics }
							});
						}
						
					}else if(obj.event === 'videoClick'){
						if(obj.data.image != ''){
							layer.photos({
								anim: 0,
								shade: [0.1, '#333'],
							    photos: { "data": obj.data.pics }
							});
						}
						
					}
				});
				//监听单元格编辑
				table.on('edit(test)', function(obj) {
					var value = obj.value, //得到修改后的值
						data = obj.data, //得到所在行所有键值
						field = obj.field; //得到字段
					if (!check_validate1(value)) {
						layer.msg('你必须输入数字');
						tableIns.reload()
					} else {
						sort(obj, tableIns)
					}


				});
				

				element.on('tab(test)', function(data){
				  var videoIns = table.render({
				  	id: 'videoReload',
				  	elem: '#video',
				  	url: "{:url('lists')}",
				  	method: "POST",
				  	request: {
				  		pageName: 'offset', //页码的参数名称，默认：page
				  		limitName: 'limit' //每页数据量的参数名，默认：limit
				  	},
				  	where: {
				  		is_school_msg: {$Think.session.schoolInfo.id},
				  		type:2
				  	},
				  	toolbar: '#videoToolbar',
				  	cols: [
				  		[{
				  			type: 'checkbox',
				  			fixed: 'left',
				  			width: 80
				  		}, {
				  			field: 'sort',
				  			title: "排序",
				  			width: 80,
				  			edit: true,
				  			sort: true
				  		}, {
				  			field: 'title',
				  			title: "标题"
				  		}, {
				  			field: 'video',
				  			title: "视频",
							width: 80,
				  			templet: function(d) {
				  				return "<img src='" + url + "images/video.png' width='25'  style='cursor: pointer;' alt='点击播放视频' />";;
				  			},
							event:"videoClickPlay"
				  		}, {
				  			field: 'created_at',
				  			title: "发布日期",
				  			sort: true
				  		}, {
				  			field: 'created_at',
				  			title: "缩略图",
				  			width: 80,
				  			templet: function(d) {
				  				if (d.image) {
				  					var logoSrc = "<img src='" + d.image + "'  width='35' height='26' style='border:1px solid #ccc;box-sizing:border-box' />";
				  				} else {
				  					var logoSrc = "<img src='" + url + "images/imageno.png' width='40' />";
				  				}
				  				return logoSrc;
				  			},
				  			event:"videoClick"
				  		}, {
				  			field: 'platform',
				  			title: "来源",
				  			width: 80,
				  			templet: function(d) {
				  				if (d.platform == 1) {
				  					var check = "后台";
				  				} else if (d.platform == 2) {
				  					var check = "APP";
				  				}else if (d.platform == 3) {
				  					var check = "其他";
				  				}
				  				return check;
				  			},
				  			sort: true
				  		}, {
				  			field: 'istop',
				  			title: "置顶",
				  			width: 80,
				  			templet: function(d) {
				  				if (d.istop == 1) {
				  					var check = "<input type='checkbox' value='" + d.id +
				  						"' lay-filter='istop' lay-skin='switch' lay-text='是|否' checked>";
				  				} else if (d.istop == 0) {
				  					var check = "<input type='checkbox' value='" + d.id +
				  						"' lay-filter='istop' lay-skin='switch' lay-text='是|否'>";
				  				}
				  
				  				return check;
				  			}
				  		}, {
				  			field: 'show',
				  			title: "显示",
				  			width: 80,
				  			templet: function(d) {
				  				if (d.show == 1) {
				  					var check = "<input type='checkbox' value='" + d.id +
				  						"' lay-filter='show' lay-skin='switch' lay-text='是|否' checked>";
				  				} else if (d.show == 0) {
				  					var check = "<input type='checkbox' value='" + d.id +
				  						"' lay-filter='show' lay-skin='switch' lay-text='是|否'>";
				  				}
				  
				  				return check;
				  			}
				  		}, {
				  			fixed: 'right',
				  			title: "{:lang('action')}",
				  			toolbar: '#videoBar',
				  			width: 180
				  		}]
				  	],
				  	page: true
				  });
				  //头工具栏事件
				  table.on('toolbar(video)', function(obj) {
				  	var checkStatus = table.checkStatus(obj.config.id);
				  	switch (obj.event) {
				  		case 'getCheckLength':
				  			var data = checkStatus.data;
				  
				  			if (data.length < 1) {
				  				layer.msg('您最少选择一个选项进行操作');
				  				return false;
				  			}
				  			var ids = [];
				  			data.forEach(function(item, index) {
				  				ids.push(item.id)
				  			})
				  			parent.layer.confirm('确认要删除这些内容？', function() {
				  				$.post("{:url('delete')}", {
				  					ids: ids,
				  					user_id: "{$Think.session.admin.id}"
				  				}, function(res) {
				  					if (res.status == 1) {
				  						parent.layer.msg('删除成功', {
				  							icon: 1,
				  							time: 300
				  						}, function() {
				  							videoIns.reload()
				  						});
				  					} else {
				  						parent.layer.msg(res.message)
				  					}
				  				})
				  			});
				  
				  			break;
				  		case 'add':
				  			parent.layer.open({
				  				title: "视频添加",
				  				type: 2,
				  				area: ['1000px', '680px'],
				  				content: "{:url('addVideo')}",
				  				success: function() {
				  					top.layerFrameConfig.iframeB = {
				  						info: videoIns
				  					}
				  				}
				  			});
				  			break;
				  	};
				  });
				  //监听行工具事件
				  table.on('tool(video)', function(obj) {
				  	var data = obj.data;
				  	var param = {
				  		ids: data.id,
				  		user_id: "{$Think.session.admin.id}"
				  	}
				  	if (obj.event === 'del') {
				  		parent.layer.confirm('真的要删除这条内容么？', function(index) {
				  			$.post("{:url('delete')}", param, function(res) {
				  				if (res.code == 0) {
				  					parent.layer.msg('删除成功', {
				  						icon: 1,
				  						time: 300
				  					}, function() {
				  						parent.layer.close(index);
				  						videoIns.reload()
				  					});
				  				} else {
				  					parent.layer.msg(res.message)
				  				}
				  			})
				  
				  		});
				  	} else if (obj.event === 'edit') {
				  		parent.layer.open({
				  			title: "{:lang('edit')}",
				  			type: 2,
				  			area: ['1000px', '680px'],
				  			content: "{:url('editVideo')}?id=" + data.id,
				  			success: function() {
				  				top.layerFrameConfig.iframeB = {
				  					info: videoIns
				  				}
				  			}
				  		});
				  	} else if (obj.event === 'view') {
				  		parent.layer.open({
				  			title: "详情",
				  			type: 2,
				  			area: ['800px', '680px'],
				  			content: "{:url('view')}?id=" + data.id,
				  			success: function() {
				  				top.layerFrameConfig.iframeB = {
				  					info: videoIns
				  				}
				  			}
				  		});
				  	}else if(obj.event === 'nameClick'){
				  		if(obj.data.image != ''){
				  			layer.photos({
				  				anim: 0,
				  				shade: [0.1, '#333'],
				  			    photos: { "data": [{"src": obj.data.image}] }
				  			});
				  		}
				  		
				  	}else if(obj.event === 'videoClick'){
				  		if(obj.data.image != ''){
				  			layer.photos({
				  				anim: 0,
				  				shade: [0.1, '#333'],
				  			    photos: { "data": [{"src": obj.data.image}] }
				  			});
				  		}
				  		
				  	}else if(obj.event === 'videoClickPlay'){
				  		if(obj.data.video){
							parent.layer.open({
							  type: 2,
							  area: ['800px', '600px'],
							  content: obj.data.video
							});
						}
				  		
				  	}
				  });
					//是否显示
					form.on('switch(show)', function(obj){
						var data = {
							id:this.value,
							status:obj.elem.checked?1:0
						}
						$.post("{:url('show')}",data,function(res){
							if(res.status == 1){
								notice.msg('设置成功', {
									icon: 1,
									timeout:1000
								});
							}else{
								notice.msg(res.message, {
									icon: 2
								});
								videoIns.reload()
							}
						})
					});
					//是否置顶
					form.on('switch(istop)', function(obj){
						var data = {
							id:this.value,
							status:obj.elem.checked?1:0
						}
						$.post("{:url('top')}",data,function(res){
							if(res.status == 1){
								notice.msg('设置成功', {
									icon: 1,
									timeout:1000
								});
							}else{
								notice.msg(res.message, {
									icon: 2
								});
								videoIns.reload()
							}
						})
					});
				});
				
				
				//是否显示
				form.on('switch(show)', function(obj){
					var data = {
						id:this.value,
						status:obj.elem.checked?1:0
					}
					$.post("{:url('show')}",data,function(res){
						if(res.status == 1){
							notice.msg('设置成功', {
								icon: 1,
								timeout:1000
							});
						}else{
							notice.msg(res.message, {
								icon: 2
							});
							tableIns.reload()
						}
					})
				});
				//是否置顶
				form.on('switch(istop)', function(obj){
					var data = {
						id:this.value,
						status:obj.elem.checked?1:0
					}
					$.post("{:url('top')}",data,function(res){
						if(res.status == 1){
							notice.msg('设置成功', {
								icon: 1,
								timeout:1000
							});
						}else{
							notice.msg(res.message, {
								icon: 2
							});
							tableIns.reload()
						}
					})
				});
				form.on('submit(picSerach)', function(data) {
					//执行重载
					table.reload('testReload', {
							method: "POST",
							request: {
								pageName: 'offset', //页码的参数名称，默认：page
								limitName: 'limit' //每页数据量的参数名，默认：limit
							},
							where: {
								type:1,
								is_school_msg: {$Think.session.schoolInfo.id},
								keywords:data.field.title,
							},
					        page: {
					          curr: 1 //重新从第 1 页开始
					        }
					});
					return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
				});
				form.on('submit(videoSerach)', function(data) {
					//执行重载
					table.reload('videoReload', {
							method: "POST",
							request: {
								pageName: 'offset', //页码的参数名称，默认：page
								limitName: 'limit' //每页数据量的参数名，默认：limit
							},
							where: {
								type:2,
								is_school_msg: {$Think.session.schoolInfo.id},
								keywords:data.field.title,
							},
					        page: {
					          curr: 1 //重新从第 1 页开始
					        }
					});
					return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
				});
				function sort(obj,tableIns){
					$.post("{:url('sort')}",obj.data,function(res){
						if(res.status == 1){
							if(res.status == 1){
								notice.msg('设置成功', {
									icon: 1,
									timeout:1000
								});
							}else{
								notice.msg(res.message, {
									icon: 2
								});
								tableIns.reload()
							}
						}
					})
				}
				$(function(){
					
					$("#picRest").click(function(){
						//执行重载
						$("#title1").val("");
						table.reload('testReload', {
								method: "POST",
								request: {
									pageName: 'offset', //页码的参数名称，默认：page
									limitName: 'limit' //每页数据量的参数名，默认：limit
								},
								where: {
									type:1,
									is_school_msg: {$Think.session.schoolInfo.id},
									keywords:"",
								},
						        page: {
						          curr: 1 //重新从第 1 页开始
						        }
						});
						return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
						
					})
					$("#videoRest").click(function(){
						$("#title2").val("");
						//执行重载
						table.reload('videoReload', {
								method: "POST",
								request: {
									pageName: 'offset', //页码的参数名称，默认：page
									limitName: 'limit' //每页数据量的参数名，默认：limit
								},
								where: {
									type:2,
									is_school_msg: {$Think.session.schoolInfo.id},
									keywords:"",
								},
						        page: {
						          curr: 1 //重新从第 1 页开始
						        }
						});
						return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
						
					})
					
				})
			});
		</script>
	</body>
</html>
